// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:"",
    goods:'',
    goodsType:'',
    select:'',
    centerList:[{id:1,text:'日常用品',imgSrc:'/icon/richang1.png',type:'richang'},
    {id:2,text:'文具',imgSrc:'/icon/wenju1.png',type:'wenju'},
    {id:3,text:'手工制品',imgSrc:'/icon/shougong1.png',type:'shougong'},
    {id:4,text:'纪念品',imgSrc:'/icon/jinian1.png',type:'jinian'},
]
  },
async onLoad(){
    const db=wx.cloud.database()
    let count=await db.collection('goods').count()
    count=count.total
    let all=[]
    for (let i=0;i<count;i+=20){
        let list=await db.collection('goods').skip(i).get()
        all = all.concat(list.data)
    }
    console.log(all);

        this.setData({
        goods:all,
        goodsType:all
        })
},

  changeInput(e){
    console.log(e.detail.value)
    
  },
handleFilter(e){
    const a=e.currentTarget.dataset.type
    const id=e.currentTarget.dataset.id
    const List=this.data.centerList
    List.map(item=>{
        if(item.id===id){
            item.imgSrc=item.imgSrc.replace('1','2')
            console.log(item.imgSrc)
        }else{
            item.imgSrc=item.imgSrc.replace('2','1')
        }
    })
    this.setData({
        centerList:List
    })
    const goodsType=this.data.goods.filter(item=>{
          return item.type==a
      })
      this.setData({
        goodsType:goodsType
      })

  },
  enter(e){
   const a=e.currentTarget.dataset._id
   console.log(e.currentTarget.dataset._id)
   wx.navigateTo({
     url: '/pages/mall/goods_detail/goods_detail?id='+a
   })
  },
})